package gov.kqqzyyy.monkey.pharmacyscreen.code.mytools;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.util.concurrent.TimeUnit;

import gov.kqqzyyy.monkey.pharmacyscreen.R;
import gov.kqqzyyy.monkey.pharmacyscreen.code.service.APIService;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Monkey on 2017/11/1.
 * Service工具类
 */

public class MyServiceUtil {
    
    private static final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.applicationContext);
    private static final String serverAdd = sharedPreferences.getString("server_address", MyApplication.applicationContext.getString(R.string.default_server));
    private static final String mBaseUrl = "http://" + serverAdd + "/api/API/";

    private static final OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .build();
    private static final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(mBaseUrl)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .build();

    private static final APIService apiService = retrofit.create(APIService.class);

    static Call<String> getSystemTimeCall() {
        return apiService.getSystemTime();
    }

    public static Call<String> getYFCKCall() {
        return apiService.getYFCK();
    }

    static Call<String> getPatientsCall(int yfsb, String yfck) {
        return apiService.getPatients(yfsb, yfck);
    }

    public static Call<String> updateJHPBCall(String cfhm) {
        return apiService.updateJHPB(cfhm);
    }

    public static Call<String> getAllHJBR() {
        return apiService.getAllHJBR();
    }

    public static Call<String> updateXYJHPB(String cfhm) {
        return apiService.updateXYJHPB(cfhm);
    }


}
